/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-06-01 17:20:03
 * @LastEditTime : 2023-06-01 17:33:20
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\TwoRouter\SampleEnclosure.jsx
 * @Description  :
 */
import { API_LIST } from '../../../Api/Api'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'

export const SampleEnclosure = async ({ OptionsEvent, oneData, Permission, actionRef }) => {
    let dataList = {
        hideInSearch: true,
        pageSize: 10,
        params: {},
        get: API_LIST([oneData.uuid])['getSampleAttachments'],
        added: 'posSampleAttachments',
        initialValues: { uuid: oneData.uuid, sampleUuid: oneData.uuid },
        options: [<AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="添加附件" />],
        columns: [
            {
                dataIndex: 'uuid',
                title: 'uuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                dataIndex: 'sampleUuid',
                title: 'sampleUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                title: '附件名称',
                dataIndex: 'tableName',
                search: false,
                type: 'hidden',
                hideInAdded: true,
                hideInModify: true,
                render: (_, { attachment }) => <div>{attachment.originalName}</div>,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '样品附件',
                valueType: 'upload',
                valueFile: [1],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '样品附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, attachment } = record
                    const { fileUrl } = attachment
                    return [
                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />,
                        Permission.findIndex(v => v.uuid === 'd71431a1-0a60-4caf-868c-77c70b3d925d') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url="SampleAttachments"
                                uuid={uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return dataList
}
